package com.css.fxfzaqbz.modules.base.controller;


import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.base.entity.BuildingVulnerability;
import com.css.fxfzaqbz.modules.base.queryParams.BuildingVulnerabilityQueryParams;
import com.css.fxfzaqbz.modules.base.service.BuildingVulnerabilityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @create 2022-08-11 14:45
 * 建筑物易损性
 */
@RestController
@RequestMapping("/buildingVulnerability")
@Slf4j
public class BuildingVulnerabilityController {

    @Resource
    BuildingVulnerabilityService buildingVulnerabilityService ;

    /**
     * 查询
     * @param buildingVulnerability
     * @return
     */
    @GetMapping("/getPage")
    public RestResponse getPage(BuildingVulnerability buildingVulnerability){
        RestResponse restResponse = null;
        try{
            List<BuildingVulnerability> page=buildingVulnerabilityService.getPage(buildingVulnerability);
            restResponse = RestResponse.succeed(page);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 修改
     * @param list
     * @return
     */
    @PostMapping("/update")
    public RestResponse update(@RequestBody List<BuildingVulnerability> list){
        RestResponse restResponse = null;
        try{
            buildingVulnerabilityService.update(list);
            restResponse = RestResponse.succeed("修改成功");
        }catch (Exception e){
            String errormessage="修改失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 保存
     * @param vulnerability
     * @return
     */
    @PostMapping("/save")
    public RestResponse save(@RequestBody BuildingVulnerability vulnerability){

           return buildingVulnerabilityService.save(vulnerability);
    }

    /**
     * 导出
     * @param response
     */
    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response,BuildingVulnerability buildingVulnerability){
        RestResponse restResponse = null;
        try {
            buildingVulnerabilityService.exportExcel(response,buildingVulnerability);
            restResponse = RestResponse.succeed("导出成功");
        } catch (Exception e) {
            String errormessage = e.getMessage();
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        ///return restResponse;
    }

    @PostMapping("/importExcel")
    public RestResponse importExcel(MultipartFile file,BuildingVulnerability buildingVulnerability) throws IOException {
        return buildingVulnerabilityService.importExcel(file,buildingVulnerability);

    }
}
